import {users} from "../../../database/admin-users.js";


window.addEventListener('load', function () {
    
    //获取页面元素
    let usernameD=document.getElementById('username');
    let passwordD=document.getElementById('password');

    //验证函数
    function TrueorFalse(){
       //获取用户输入的值
       let usernameV=usernameD.value.trim();
       let passwordV=passwordD.value.trim();
       for (let i = 0; i < users.length; i++) {
            var userObj = users[i];

            if(userObj.account === usernameV && userObj.password === passwordV){
                var userObject = {
                    id:userObj.id,
                    username:usernameV,
                    avatar:"/ourmall-admin/src/static/images/avatar.png",
                    role : userObj.role,
                };
                localStorage.setItem('user-info',JSON.stringify(userObject));
                //跳转页面待定
                window.location.href='../../../index.html';
                return ;
            }
        }

        alert('账号或密码错误，请重新输入！');
    }


    //登录按钮点击事件
    let loginBtn=document.getElementById('loginBtn');
    loginBtn.addEventListener('click',function () {
        TrueorFalse();
    })
})